﻿using Heroius.Extension.Desktop;
using Heroius.Files;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PicWaterMarker
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            PathHelper.CreateDirectory(configpath);
            if (File.Exists(configpath))
            {
                EntitySilo silo = new EntitySilo();
                silo.Load(configpath);
                silo.Fetch("config", config);
            }
            DataContext = config;
        }

        readonly string configpath = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\\EnvSafe\\PicWaterMarker\\config.xml";

        public ImageHandlerConfiguration config { get; set; } = new ImageHandlerConfiguration();

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                new ImageHandler().ProcessRequest(config);
                EntitySilo silo = new EntitySilo();
                silo.Store("config", config);
                silo.Save(configpath);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
